package org.jeecg.modules.product.job.ticket.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.product.job.ticket.entity.TbJobTicket;
import org.jeecg.modules.product.job.ticket.mapper.*;
import org.jeecg.modules.product.job.ticket.service.ITbJobTicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Description: 电子作业票
 * @Author: jeecg-boot
 * @Date:   2024-08-08
 * @Version: V1.0
 */
@Service
public class TbJobTicketServiceImpl extends ServiceImpl<TbJobTicketMapper, TbJobTicket> implements ITbJobTicketService {

	@Autowired
	private TbJobTicketMapper tbJobTicketMapper;
	@Autowired
	private TbJobTicketAuditRecordMapper tbJobTicketAuditRecordMapper;
	@Autowired
	private TbJobTicketJsaAnalyzeMapper tbJobTicketJsaAnalyzeMapper;
	@Autowired
	private TbJobTicketGasAnalysisMapper tbJobTicketGasAnalysisMapper;
	@Autowired
	private TbJobTicketMeasureRecordMapper tbJobTicketMeasureRecordMapper;
	@Autowired
	private TbJobTicketExamineRecordMapper tbJobTicketExamineRecordMapper;
	@Autowired
	private TbJobTicketSecurityDisclosureRecordMapper tbJobTicketSecurityDisclosureRecordMapper;
	@Autowired
	private TbJobTicketCourseRecordMapper tbJobTicketCourseRecordMapper;
	@Autowired
	private TbJobTicketProblemRecordMapper tbJobTicketProblemRecordMapper;
	@Autowired
	private TbJobTicketViolationCaptureMapper tbJobTicketViolationCaptureMapper;
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delMain(String id) {
		tbJobTicketAuditRecordMapper.deleteByMainId(id);
		tbJobTicketJsaAnalyzeMapper.deleteByMainId(id);
		tbJobTicketGasAnalysisMapper.deleteByMainId(id);
		tbJobTicketMeasureRecordMapper.deleteByMainId(id);
		tbJobTicketExamineRecordMapper.deleteByMainId(id);
		tbJobTicketSecurityDisclosureRecordMapper.deleteByMainId(id);
		tbJobTicketCourseRecordMapper.deleteByMainId(id);
		tbJobTicketProblemRecordMapper.deleteByMainId(id);
		tbJobTicketViolationCaptureMapper.deleteByMainId(id);
		tbJobTicketMapper.deleteById(id);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for(Serializable id:idList) {
			tbJobTicketAuditRecordMapper.deleteByMainId(id.toString());
			tbJobTicketJsaAnalyzeMapper.deleteByMainId(id.toString());
			tbJobTicketGasAnalysisMapper.deleteByMainId(id.toString());
			tbJobTicketMeasureRecordMapper.deleteByMainId(id.toString());
			tbJobTicketExamineRecordMapper.deleteByMainId(id.toString());
			tbJobTicketSecurityDisclosureRecordMapper.deleteByMainId(id.toString());
			tbJobTicketCourseRecordMapper.deleteByMainId(id.toString());
			tbJobTicketProblemRecordMapper.deleteByMainId(id.toString());
			tbJobTicketViolationCaptureMapper.deleteByMainId(id.toString());
			tbJobTicketMapper.deleteById(id);
		}
	}

	@Override
	public List<Map> queryJobCountByEventIdAndJobType(TbJobTicket tbJobTicket) {
		return tbJobTicketMapper.queryJobCountByEventIdAndJobType(tbJobTicket.getEventsId(),tbJobTicket.getJobType());
	}

}
